<template>
  <div class="population">
    <el-container>
      <el-input
        style="width: 20%"
        placeholder="预约档案号/姓名"
        v-model="parameter.content"
        clearable
      ></el-input>
      <el-button
        type="primary"
        size="mini"
        @click="onSubmit"
        icon="el-icon-search"
        round
        >查询</el-button
      >
    </el-container>
    <el-table style="width: 100%" align="center"
      v-loading="loading"
      element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading"
     :data="AllUser">
      <el-table-column label="预约档案号" prop="tmemberId" width="120">
      </el-table-column>
      <el-table-column label="姓名" prop="name" width="100"> </el-table-column>
      <el-table-column label="性别" prop="sex" width="100">
        <template slot-scope="scope">
          <span v-if="(scope.row.sex == 0)"> 女 </span>
          <span v-if="(scope.row.sex == 1)"> 男 </span>
        </template>
      </el-table-column>
      <el-table-column label="年龄" prop="age" width="100"> </el-table-column>
      <el-table-column label="分类方式" prop="classification" width="150">
      </el-table-column>
      <el-table-column label="人群分类" prop="peopleClassify" width="150">
      </el-table-column>
      <el-table-column label="健康管理师" prop="udr" width="270">
        <template slot-scope="scope">
          <span v-if="scope.row.udr == null"> 未定义 </span>
          <span v-if="scope.row.udr != null"> {{ scope.row.udr }} </span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="300">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            v-if="scope.row.status == 0"
            @click.native="update(scope.row)"
            icon="el-icon-edit"
          >
            确认分类信息
          </el-button>
          <el-button
            type="success"
            size="mini"
            v-if="scope.row.status == 1"
            @click.native="success()"
            icon="el-icon-check"
          >
            已确认分类信息
          </el-button>
          <el-button
            type="danger"
            size="mini"
            @click.native="deleteRow(scope.row, scope.$index, AllUser)"
            icon="el-icon-delete"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="parameter.page"
      :page-sizes="[2, 5, 10, 20]"
      :pager-count="9"
      background
      :page-size.sync="parameter.num"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
  </div>
</template>

<script>
import Vue from "vue";
import axios from "axios";
export default Vue.extend({
  data() {
    return {
      loading: true,
      AllUser: [],
      parameter: {
        page: 1,
        num: 5,
        content: "",
      },
      total: 0,
    };
  },
  methods: {
    //先查看是否进行了人群分类 无直接删除则前面的问卷可删 有则进行查询有木有进行了分案制定
    deleteRow(scope, index, allList) {
      if (scope.status != 1) {
        this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            allList.splice(index, 1);
            //删除分类表里面的技术
            axios
              .post("/api/lqHealth/deleteClassIf", { tmerber: id })
              .then((res) => {
                console.log(res.data);
              });
            if (allList.length == 0) {
              this.parameter.page += 1;
              this.load();
            }
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
            });
          });
      } else {
        let id = scope.tmemberId;
        axios
          .post("/api/lqHealth/chaInterventionprogrammes", { tmerber: id })
          .then((res) => {
            if (res.data > 0) {
              this.$message({
                type: "error",
                message: "本会员已进行方案制定要删除的话先删除随访日记中的初始化记录方案",
              });
            } else {
              this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
              })
                .then(() => {
                  allList.splice(index, 1);
                  //删除分类表里面的技术
                  axios
                    .post("/api/lqHealth/deleteClassIf", { tmerber: id })
                    .then((res) => {
                      console.log(res.data);
                    });
                  if (allList.length == 0) {
                    this.parameter.page += 1;
                    this.load();
                  }
                  this.$message({
                    type: "success",
                    message: "删除成功!",
                  });
                })
                .catch(() => {
                  this.$message({
                    type: "info",
                    message: "已取消删除",
                  });
                });
            }
          });
      }
    },
    handleSizeChange() {
      this.load();
    },
    handleCurrentChange() {
      this.load();
    },
    onSubmit() {
      this.load();
    },
    update(Scope) {
      this.$router.push({
        path: "/home/GroupPagingInformation?breadcrunmbName=健康干预,人群分类,分类详情",
        query: { user_scpoe: "user_scpoe", value: Scope },
      });
    },
    load() {
      axios
        .post("/api/lqHealth/selectAlltinterpose", this.parameter)
        .then((res) => {
          this.AllUser = res.data.list;
          this.parameter.page = res.data.pageNum;
          this.parameter.num = res.data.pageSize;
          this.total = res.data.total;

          //加载样式
        // const loading = this.$loading({
        //   lock: true,
        //   text: 'Loading',
        //   spinner: 'el-icon-loading',
        //   background: 'rgba(0, 0, 0, 0.7)'
        // });
        setTimeout(() => {
          this.loading=false;
        }, 1000);
        });
    },
    success() {
      this.$message({
        type: "success",
        message: "已确认分类信息!",
      });
    },
  },
  created() {
    this.load();
  },
});
</script>

<style scoped>
</style>